<?php
/**
 * Created by PhpStorm.
 * User: liuxiu
 * Date: 2022/8/17
 * Time: 15:46
 */

namespace business\base\services;


use yii\db\Query;
use yii\redis\Cache;

class HighFrequencyWordService
{
    public function getList() {
        $key = 'opensearch:bigdata:developer:high_frequency_word';
        $redis = new Cache();
        $redis->redis = \Yii::$app->get('redis');
        $content = $redis->get($key);
        if (!empty($content)) {
            return json_decode($content, true);
        } else {

            $list = (new Query())->from('`b2b_search`.`high_frequency_word`')
                ->select('keyword')
                ->where(['is_deleted' => 0])
                ->createCommand()
                ->queryColumn();
            if (!empty($list)) {
                $redis->set($key, json_encode($list, JSON_UNESCAPED_UNICODE), 7200);
            } else {
                $list = [];
            }
            return $list;
        }
    }
}